package com.hele.sts.action;

import java.util.List;
import java.util.Map;

import com.hele.sts.dao.*;
import com.opensymphony.xwork2.ActionContext;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hele.sts.pub.SelectOption;
import com.opensymphony.xwork2.Action;
import org.springframework.beans.factory.annotation.Autowired;

public class BaseInfoAction implements Action{
	private static final Logger logger = LoggerFactory.getLogger(BaseInfoAction.class);
	private String nbxh;
	private Qyhznr qyhznr;
	private Qyajb qyajb;
	private String qylxmc;
	private String hymc;
	private String djjgmc;
	private String gxdwmc;
	private List<Qyzfjzmlb> qyjnmlList; 
	private List<XtServer> xtServerList;

	private DaArchTid daArchTid;
	private String printContent;

	@Autowired
	private XtLogDao xtLogDao;
	
	@Override
	public String execute() throws Exception {
		logger.debug("nbxh="+nbxh);

        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        String userId = (String) session.get("userid");
        String username = (String)session.get("user_name");

        qyhznr = QyhznrDao.load(nbxh);
		//logger.debug(qyhznr.toString());
		if(qyhznr==null){
			qyhznr=QyhznrDao.loadBfTj(nbxh);
		}
		
		if(qyhznr!=null){
			qylxmc = SelectOption.getCodeVal("bm_qylx", qyhznr.getQylx());
			hymc = SelectOption.getCodeVal("bm_hy", qyhznr.getHy());
			djjgmc = SelectOption.getCodeVal("bm_djjg", qyhznr.getDjjg());
			gxdwmc = SelectOption.getCodeVal("bm_gxdw", qyhznr.getGxdw());
		}
		
		qyajb = QyajbDao.load(nbxh);
		qyjnmlList = TreeDao.getJnmlList(nbxh);
		daArchTid = DaArchTidDao.queryDaxxByNbxh(nbxh);
		if("jnmlList".equals(printContent)){
            xtLogDao.insertLog("业务日志","打印企业卷内目录",userId,username,"成功","用户："+userId+" 打印卷内目录："+nbxh,this.getClass().getName());
            return "jnmlListPrint";
		}
		if("cover".equals(printContent)){
			String qylx = qyhznr.getQylx();
			int qylxInt = 0;
			if(qylx==null) {
				qylxInt = 0;
			} else {
				qylx = qylx.substring(0, 1);
			}
			qylxInt = Integer.parseInt(qylx);
			if(qylxInt>=1&&qylxInt<=5) {
				qylxmc = "内资企业类";
			} else if(qylxInt==6 || qylxInt == 7) {
				qylxmc = "外资企业类";
			} else if(qylxInt == 8) {
				qylxmc = "集团企业类";
			} else if(qylxInt == 9 ||qylxInt == 0 ) {
				qylxmc = "其他";
			}
			//qylxmc = SelectOption.getCodeVal("bm_qylx", qylx);
            xtLogDao.insertLog("业务日志","打印封面",userId,username,"成功","用户："+userId+" 打印封面："+nbxh,this.getClass().getName());
            return "coverPrint";
		}
		
		xtServerList = XtServerDao.getServerListForJnml(nbxh);

        xtLogDao.insertLog("业务日志","查询企业基本信息",userId,username,"成功","用户："+userId+" 查询企业基本信息："+nbxh,this.getClass().getName());
		return "success";
	}

	/**
	 * @return the nbxh
	 */
	public String getNbxh() {
		return nbxh;
	}

	/**
	 * @param nbxh the nbxh to set
	 */
	public void setNbxh(String nbxh) {
		this.nbxh = nbxh;
	}

	/**
	 * @return the qyhznr
	 */
	public Qyhznr getQyhznr() {
		return qyhznr;
	}

	/**
	 * @param qyhznr the qyhznr to set
	 */
	public void setQyhznr(Qyhznr qyhznr) {
		this.qyhznr = qyhznr;
	}

	/**
	 * @return the qyajb
	 */
	public Qyajb getQyajb() {
		return qyajb;
	}

	/**
	 * @param qyajb the qyajb to set
	 */
	public void setQyajb(Qyajb qyajb) {
		this.qyajb = qyajb;
	}

	/**
	 * @return the qylxmc
	 */
	public String getQylxmc() {
		return qylxmc;
	}

	/**
	 * @param qylxmc the qylxmc to set
	 */
	public void setQylxmc(String qylxmc) {
		this.qylxmc = qylxmc;
	}

	/**
	 * @return the hymc
	 */
	public String getHymc() {
		return hymc;
	}

	/**
	 * @param hymc the hymc to set
	 */
	public void setHymc(String hymc) {
		this.hymc = hymc;
	}

	/**
	 * @return the djjgmc
	 */
	public String getDjjgmc() {
		return djjgmc;
	}

	/**
	 * @param djjgmc the djjgmc to set
	 */
	public void setDjjgmc(String djjgmc) {
		this.djjgmc = djjgmc;
	}

	/**
	 * @return the gxdwmc
	 */
	public String getGxdwmc() {
		return gxdwmc;
	}

	/**
	 * @param gxdwmc the gxdwmc to set
	 */
	public void setGxdwmc(String gxdwmc) {
		this.gxdwmc = gxdwmc;
	}

	/**
	 * @return the qyjnmlList
	 */
	public List<Qyzfjzmlb> getQyjnmlList() {
		return qyjnmlList;
	}

	/**
	 * @param qyjnmlList the qyjnmlList to set
	 */
	public void setQyjnmlList(List<Qyzfjzmlb> qyjnmlList) {
		this.qyjnmlList = qyjnmlList;
	}

	/**
	 * @return the xtServerList
	 */
	public List<XtServer> getXtServerList() {
		return xtServerList;
	}

	/**
	 * @param xtServerList the xtServerList to set
	 */
	public void setXtServerList(List<XtServer> xtServerList) {
		this.xtServerList = xtServerList;
	}

	/**
	 * @return the printContent
	 */
	public String getPrintContent() {
		return printContent;
	}

	/**
	 * @param printContent the printContent to set
	 */
	public void setPrintContent(String printContent) {
		this.printContent = printContent;
	}


	public DaArchTid getDaArchTid() {
		return daArchTid;
	}

	public void setDaArchTid(DaArchTid daArchTid) {
		this.daArchTid = daArchTid;
	}
}
